package com.pzl.mylistview;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by zl.peng on 2016-03-07.
 */
public class MyListViewAdapter implements Adapter {
    private Context context;
    private ArrayList<HashMap<String, Object>> data;

    public MyListViewAdapter(Context context, ArrayList<HashMap<String, Object>> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        if (data == null) return 0;
        return data.size();
    }

    @Override
    public View getView(int position, View reuseView, ViewGroup parent) {
        View view;
        if (reuseView == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item, parent, false);
        } else {
            view = reuseView;
        }
        ImageView iv = (ImageView) view.findViewById(R.id.iv);
        TextView tv = (TextView) view.findViewById(R.id.tv);
       // iv.setImageBitmap((Bitmap) data.get(position).get("iv"));
        tv.setText((String) data.get(position).get("tv"));
        return view;
    }
}
